/**
 * Project: greenline-epay-web-home
 * 
 * File Created at 2013-4-19
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.greenline.pay.web.common.utils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.greenline.common.util.FenToYuan;
import com.greenline.pay.web.common.cookie.UserCookieUtil;

/**
 * @Type WebUtils
 * @Desc
 * @author jianyun.zheng
 * @date 2013-4-19
 * @Version V1.0
 */
public class WebUtils {
    @Resource
    private HttpServletRequest request;

    /**
     * 是否登录
     * 
     * @return
     */
    public boolean isLogin() {
        return UserCookieUtil.isLogin(request);
    }

    /**
     * 获取当前页面url,需要加异常处理
     * 
     * @param request
     * @return String
     */
    public String getCuurentUrl() {
        return HttpUtils.getRequestUrl(request);
    }

    public String getCookieUserType() {
        return UserCookieUtil.getUserType(request);
    }

    /**
     * cookie中的昵称（如果昵称不存在取loginId）
     * 
     * @return
     */
    public String getNickName() {
        String nickName = UserCookieUtil.getNickName(request);
        if (StringUtils.isNotBlank(nickName)) {
            return nickName;
        }
        return UserCookieUtil.getLoginId(request);
    }

    public static String strFenToYuan(String fen) {
        if (StringUtils.isBlank(fen) || "0".equals(fen)) {
            return "0";
        }
        FenToYuan ft = new FenToYuan();
        return ft.formatFenToYuanString(fen);
    }

    public static String fenToYuan(Long fen) {
        if (null == fen || 0 == fen) {
            return "0";
        }
        FenToYuan ft = new FenToYuan();
        return ft.formatFenToYuanString(String.valueOf(fen));
    }
}
